<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <title>会员登录 - <?php echo config('website.site_name')?></title>
        <link rel="stylesheet" type="text/css" href="__LIBS__/layui/css/layui.css" />
        <link rel="stylesheet" type="text/css" href="__USER__/css/login.css" />
    </head>
    <body>
        <div class="m-login-bg">
            <div class="m-login">
                <h3>会员登录-<?php echo config('website.site_name')?></h3>
                <div class="m-login-warp">
                    <form class="layui-form" action="{:url('user/index/login')}" method="post">
                        <div class="layui-form-item">
                            <input type="text" name="username" lay-verify="required" autocomplete="off" placeholder="请输入账号" class="layui-input">
                        </div>
                        <div class="layui-form-item">
                            <input type="password" name="password" lay-verify="required" autocomplete="off" placeholder="请输入密码" class="layui-input">
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <input type="text" name="captcha" lay-verify="required" autocomplete="off" placeholder="验证码" class="layui-input">
                            </div>
                            <div class="layui-inline">
                                <img class="verifyImg" src="{:url('user/index/captcha')}" onclick="this.src='{:url('user/index/captcha')}?rand='+Math.random()" />
                            </div>
                        </div>
                        <div class="layui-form-item m-login-btn">
                            <div class="layui-inline">
                                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="login">登录</button>
                            </div>
                            <div class="layui-inline">
                                <a href="/user/index/register" class="layui-btn layui-btn-primary">注册</a>
                            </div>
                        </div>
                    </form>
                </div>
                <p class="copyright"><?php echo config('website.site_copyright')?></p>
            </div>
        </div>
        <script src="__LIBS__/layui/layui.js"></script>
        <script>
        layui.use(['layer', 'form', 'jquery'], function(){
            var layer = layui.layer,
                form  = layui.form,
                $     = layui.jquery;
            form.on('submit(login)', function(data) {
                var index = layer.msg('登录中，请稍候', {
                    icon: 16,
                    time: false,
                    shade: 0.3
                });
                $.ajax({
                    url: data.form.action,
                    type: data.form.method,
                    dataType: 'json',
                    data: $(data.form).serialize(),
                    success: function(result) {
                        if (result.code === 1) {
                            location.href = result.url;
                        } else {
                            $('.captcha img').attr('src', '{:url("user/index/captcha")}?rand='+Math.random());
                            layer.close(index);
                            layer.msg(result.msg);
                        }
                    },
                    error: function (xhr, state, errorThrown) {
                        layer.close(index);
                        layer.msg(state + '：' + errorThrown);
                    }
                });
                return false;
            });
        });
        </script>
    </body>
</html>